function e(e) {
    var o = !0;
    return 11 != e.length && (o = !1), /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(16[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/.test(e) || (o = !1), 
    o;
}

var o = require("../../utils/api.js");

getApp();

Page({
    data: {
        orderType: "cash",
        animationData: {},
        isShowSign: !1,
        showSign: !1,
        refundSign: "",
        signlist: [ {
            id: "0",
            name: "未收货"
        }, {
            id: "1",
            name: "已收货"
        } ],
        isShowReason: !1,
        showReason: !1,
        refundReason: "",
        reasonlist: [ {
            id: "0",
            name: "不想买了"
        }, {
            id: "1",
            name: "拍错了，重新下单"
        }, {
            id: "2",
            name: "商品质量原因"
        }, {
            id: "3",
            name: "商品与描述不符"
        }, {
            id: "4",
            name: "商品破损"
        }, {
            id: "5",
            name: "其他"
        } ],
        goods: "",
        order: "",
        phone: "",
        explain: !1,
        text: ""
    },
    onLoad: function(e) {
        var a = this;
        wx.setNavigationBarColor({
            frontColor: wx.getStorageSync("basic").topcolor,
            backgroundColor: wx.getStorageSync("basic").topbg
        }), o.backGoodsInfo({
            id: e.id,
            gid: e.gid,
            ossid: e.ossid
        }).then(function(e) {
            console.log(e), (e.errno = 1) ? a.setData({
                goods: e.data.goods,
                order: e.data.order,
                gs: e.data.gs
            }) : wx.showToast({
                title: e.message
            });
        });
    },
    setAnimation: function() {
        var e = wx.createAnimation({
            duration: 200,
            timingFunction: "ease-out"
        });
        this.animation = e, this.animation.top(0).opacity(1).step(), this.setData({
            animationData: this.animation.export()
        });
    },
    changeRefundType: function(e) {
        var o = e.currentTarget.dataset.type;
        this.setData({
            orderType: o
        });
    },
    openSign: function() {
        var e = this;
        e.setData({
            explain: !0
        }), setTimeout(function() {
            e.setData({
                isShowSign: !0,
                showSign: !0
            });
        }, 500);
    },
    closeSign: function() {
        var e = this;
        e.setData({
            showSign: !1,
            isShowSign: !1
        }), setTimeout(function() {
            e.setData({
                explain: !1
            });
        }, 500);
    },
    radioChangeSign: function(e) {
        console.log(e.detail.value), this.setData({
            chooseSign: Number(e.detail.value),
            defaultVal: Number(e.detail.value)
        });
    },
    confirmSign: function() {
        console.log(1);
        var e = this, o = e.data.chooseSign;
        console.log(o);
        for (var a = e.data.signlist, t = 0; t < a.length; t++) a[t].id == o && (e.setData({
            refundSign: a[t].name,
            showSign: !1,
            isShowSign: !1
        }), setTimeout(function() {
            e.setData({
                explain: !1
            });
        }, 500));
    },
    openReason: function(e) {
        var o = this;
        o.setData({
            explain: !0
        }), setTimeout(function() {
            o.setData({
                isShowReason: !0,
                showReason: !0
            });
        }, 500);
    },
    closeReason: function() {
        var e = this;
        e.setData({
            showReason: !1,
            isShowReason: !1
        }), setTimeout(function() {
            e.setData({
                explain: !1
            });
        }, 500);
    },
    radioChangeReason: function(e) {
        var o = this;
        console.log(e.detail.value), o.setData({
            chooseReason: Number(e.detail.value),
            defaultVal: Number(e.detail.value)
        });
    },
    confirmReason: function() {
        for (var e = this, o = e.data.chooseReason, a = e.data.reasonlist, t = 0; t < a.length; t++) a[t].id == o && (e.setData({
            refundReason: a[t].name,
            showReason: !1,
            isShowReason: !1
        }), setTimeout(function() {
            e.setData({
                explain: !1
            });
        }, 500));
    },
    onChange: function(e) {
        console.log(e), this.setData({
            num: e.detail
        });
    },
    computeWordNum: function(e) {
        console.log(e), this.setData({
            text: e.detail.value
        });
    },
    orderUserPhone: function(e) {
        this.setData({
            phone: e.detail.value
        });
    },
    formSubmit: function(a) {
        var t = this;
        console.log(a);
        var n = a.detail.value.id, i = a.detail.value.gid, s = a.detail.value.ossid, r = a.detail.value.orderUserPhone;
        if (!e(r)) return wx.showToast({
            title: "请输入正确的电话号码",
            icon: "none"
        }), !1;
        var d = t.data.text;
        if ("" == d || void 0 == d) return wx.showToast({
            title: "请输入退款说明",
            icon: "none"
        }), !1;
        var l = t.data.refundSign;
        if ("" == l || void 0 == l) return wx.showToast({
            title: "请选择收货状态",
            icon: "none"
        }), !1;
        "未收货" == l ? l = 1 : "已收货" == l && (l = 2);
        var u = t.data.refundReason;
        if ("" == u || void 0 == u) return wx.showToast({
            title: "请选择申请原因",
            icon: "none"
        }), !1;
        var c = a.detail.formId;
        if ("cash" == t.data.orderType) g = 1; else if ("all" == t.data.orderType) var g = 2;
        var h = {
            id: n,
            gid: i,
            ossid: s,
            orderUserPhone: r,
            refundRemark: d,
            refundSign: l,
            refundReason: u,
            openid: wx.getStorageSync("openid"),
            orderType: g,
            formId: c
        };
        console.log(h), o.applyBackMoney(h).then(function(e) {
            1 == e.errno && (wx.showToast({
                title: e.message,
                icon: "none"
            }), wx.reLaunch({
                url: "../refund/refundList"
            })), console.log(e), wx.showToast({
                title: e.message,
                icon: "none"
            });
        });
    }
});